package com.polaris.live.widget.high_light.shape

import android.graphics.BlurMaskFilter
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Path
import android.graphics.RectF

/**
 * HighlightShape
 *
 * @author Created by 半仙 on 2024/6/26/026 17:32
 */
open class HighlightShape(val blurRadius: Float = 0.0f) {

    private lateinit var paint: Paint

    //clip path
    internal val path by lazy {
        Path()
    }

    init {
        paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
            isDither = true
            color = Color.WHITE
        }
        //paint blur style
        if (blurRadius > 0) {
            paint.maskFilter = BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.SOLID)
        }
    }

    protected var rect: RectF? = null

    /**
     *  init rect  child should override initRect and init path
     * */
    open fun initRect(rectF: RectF) {
        this.rect = rectF
    }

    /**
     *  draw our path
     */
    fun drawPath(canvas: Canvas) {
        rect?.run {
            if (isEmpty.not()) {
                canvas.drawPath(path, paint)
            }
        }
    }

    fun setPaint(paint: Paint) {
        this.paint = paint
    }
}